import request from '@/utils/request'

// 获取好友列表
export function getFriendList() {
  // 获取当前用户ID
  const userId = uni.getStorageSync('userId')
  return request({
    url: `/friends?user_id=${userId}`,
    method: 'GET'
  })
}

// 搜索用户
export function searchUser(username) {
  return request({
    url: `/users/search?username=${username}`,
    method: 'GET'
  })
}

// 添加好友
export function addFriend(data) {
  return request({
    url: '/friends/add',
    method: 'POST',
    data
  })
}

// 删除好友
export function deleteFriend(friendId) {
  return request({
    url: `/friends?friend_id=${friendId}`,
    method: 'DELETE'
  })
}

// 获取或创建聊天房间
export function getOrCreateChatRoom(userId) {
  return request({
    url: `/rooms/chat?user_id=${userId}`,
    method: 'POST'
  })
}